package com.lglbc.singelton;

/**
 * 饿汉模式
 */
public class EHPattern {
    public static void main(String[] args) {
        EHPatternInstance1 instance = EHPatternInstance1.getInstance();
        EHPatternInstance1 instance1 = EHPatternInstance1.getInstance();
        System.out.println(instance1 == instance);
        System.out.println(instance1.hashCode() == instance.hashCode());
    }
}

class EHPatternInstance1{
    private final static EHPatternInstance1 INSTANCE = new EHPatternInstance1();
    private EHPatternInstance1(){

    }
    public static EHPatternInstance1 getInstance(){
        return INSTANCE;
    }
}
class EHPatternInstance2{
    private  static EHPatternInstance2 INSTANCE;
    static {
        INSTANCE = new EHPatternInstance2();
    }
    private EHPatternInstance2(){

    }
    public static EHPatternInstance2 getInstance(){
        return INSTANCE;
    }
}